/*
 * @lc app=leetcode.cn id=303 lang=cpp
 *
 * [303] 区域和检索 - 数组不可变
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class NumArray
{
public:
    vector<int> dp;
    NumArray(vector<int> &nums)
    {
        dp = vector<int>(nums.size(), 0);
        dp[0] = nums[0];
        for (int i = 1; i < nums.size(); i++)
        {
            dp[i] = dp[i - 1] + nums[i];
        }
    }

    int sumRange(int left, int right)
    {
        if (left == 0)
            return dp[right];
        else
            return dp[right] - dp[left - 1];
    }
};

// int main()
// {
//     vector<int> nums = {-2,0,3,-5,2,-1};
//     NumArray arr(nums);
//     cout << arr.sumRange(0, 2) << endl;
//     return 0;
// }

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray* obj = new NumArray(nums);
 * int param_1 = obj->sumRange(left,right);
 */
// @lc code=end
